package com.zhz.crm.controller;

import com.zhz.crm.model.User;
import com.zhz.crm.service.UserService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {
    @Resource
    private UserService userService;
    @GetMapping(value = "/users")
    public List<User> findAllUsers(){
        List<User> list = userService.findAllUsers();
        return list;
    }
    @GetMapping(value = "/user/{id}")
    public User getUser(@PathVariable("id") Long usrId){
        User user = userService.getUser(usrId);
        return user;
    }
    @PostMapping(value = "/user")
    public void addUser(User user){
        userService.addUser(user);
    }
    @PutMapping(value = "/user")
    public void updateUser(User user){
        userService.updateUser(user);
    }
    @Delete(value = "/user/{id}")
    public void deleteUser(@PathVariable("id") Long usrId){
        userService.deleteUser(usrId);
    }
}
